/**
 * index 页面js2 
 */


/*根据参数的岁数输入血压提示*
 * 1 年龄小于设定的值，直接接诊
 * 2 年龄大于设定的值，查询病人信息，有血压，直接接诊
 * 3 年龄大于设定的值，查询病人信息，没有有血压，输入血压，保存成功，直接接诊
 */
var blood_index; //弹出层
function isWriteBloodPressure(row_t){
	debugger;
	if(valueArr["p_9999_9999_97"] && (row_t.agep.indexOf("岁")>=0 && row_t.agep.indexOf("月")<0)
			 && parseInt(row_t.agep)>=parseInt(valueArr["p_9999_9999_97"]) )
	{
			$.ajax({
				url : rootUrl + "/patientsearch/getpatientinfo",
				data : {
					"productid" : 100,
					"programid" :103010,
					"paramno" : 29,
					"lVAC01" : row_t.vac01
				},
				type : 'post',
				dataType : 'json',
				success : function(data) {
					if(!(data.list[0].vcj04 && data.list[0].vcj05)){ //没有血压，提示需要输入血压
						var data = {msg:valueArr["p_9999_9999_97"]+"岁以上病人需要录入血压值"}
						laytplUrl_T(myurl + "/module/blood_pressure.html",data, function(data, html) {
							blood_index = layer.open({
								type : 1,
								title :"提示",
								area : [ "400px", "250px" ],
								shade : 0.1,
								content : html,
								closeBtn : 0,
								success : function() {
									$("#blood_pressure").focus();
									$("#save_blood_pressure").off("click").on("click",function(){
										layer.msg('加载中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500,skin: 'layui-layer-msg16'}); 
										var blood = $("#blood_pressure").val();
										if(blood && checkNumber(blood.split("/")[0])&&checkNumber(blood.split("/")[1])){
											row_t.blood = blood;
											saveMoreInfo(row_t);
										}else{
											layer.msg("请输入正确的血压！",{time:3000,icon:0,skin: 'layui-layer-msg0'});
										}
									})
								}
							})
						})
					}else{ //有血压，直接接诊
						callAfterReceive(row_t);
					}
				}
			})
	}else{
		//不需要输入血压，直接接诊
		callAfterReceive(row_t);
	}
	
}

/**
 * 保存体重、血压 
 * 传入血压，只保存血压
 */
function saveMoreInfo(row_t)
{
	debugger;
	var ssy; //04 大
	var szy; //05 小
	var tz;
	if(row_t&&row_t.blood){
		ssy = row_t.blood.split("/")[0];
		szy = row_t.blood.split("/")[1];
	}
	else if(row_t.tizhong){
		tz = row_t.tizhong;
	}
	else{
		
		tz = $("#tz").val();
		var xueya = $("#xueya").val();
		if (xueya)
		{
			ssy = xueya.split("/")[0];
			szy = xueya.split("/")[1];
		}
	}
	var params = {};
	params.vaa07 = row_t.vac01;
//	params.vaa01 = row_t.vaa01;
	if(tz){
		params.vac63 = tz;
	}
	if(checkNumber(szy)&&checkNumber(ssy))
	{
		params.vcj04 = parseInt(ssy) > parseInt(szy) ? ssy : szy;
		params.vcj05 = parseInt(ssy) < parseInt(szy) ? ssy : szy;
	}
	$.ajax({
		url:rootUrl+"/clidoctor/savePatientMore",
		type:"post",
		dataType:"json",
		data:params,
		async:false,
		success:function(data)
		{
			if(data && data.result=="Success")
			{
				layer.msg("保存成功！", {time : 2000,
					icon : 1,
					skin: 'layui-layer-msg1'});
				layer.close(blood_index);	
				//输入血压保存之后，自动呼叫
				hujiao_houtai_c(row_t);
			}
			else
			{
				layer.msg("保存失败！", {time : 2000,
					icon : 2,
					skin: 'layui-layer-msg2'});
			}
		},
		error:function(a,b,c)
		{
			console.log(c);
		}
	});
}
//后台呼叫-同步方法
function hujiao_houtai_c(row_t)
{
	var isAlsoWait = false;
	var rowIds = jQuery("#patient_wait").jqGrid('getDataIDs');
	for(var j=0;j<rowIds.length;j++){
		var curRowData = jQuery("#patient_wait").jqGrid('getRowData', rowIds[j]);
		if(row_t.vac01==curRowData['vac01']){
			isAlsoWait = true;
		}
	}
	if(!isAlsoWait){
		layer.msg("该病人已经被其他医生接诊！", {time : 2000,
			icon : 2,
			skin: 'layui-layer-msg2'});
		return false;
	}
	var beginTime;
	var endTime;
	beginTime = getDay(-1)+" 23:45:00:";
	endTime = getDay(0)+" 23:59:59:";
	var jiezhenfw = valueArr.p_100_105002_100;
//	jiezhenfw = '01';
	var fenzhen=1;
	if(valueArr.p_9999_9999_102==1 || valueArr.p_9999_9999_102=="1")
	{
		fenzhen=0;
	}
	else
	{
		fenzhen=1;
	}
	$.ajax({
		url:rootUrl+"/clidoctor/hujiao_houtai",
		type:"get",
		dataType:"json",
		data:{
			vac01 : row_t.vac01,
			lPara : jiezhenfw,
			lVAC51 : 0,
			lBCK01 : $("#departmentList").find("option:selected").attr("id"),
			lBCE01 : bce01,
			BAS02 : '0001',
			fenzhen : fenzhen,
			beginTime :beginTime,
			endTime :endTime,
			lSign : 0,
			lBCK01 : bck01,
			lBCE01 : bce01,
			lBCE02 : $.cookie("loginName"),
			lBCE03 : bce03
		},
		success:function(data)
		{
			if(data)
			{
				var hujiaoRow = {};
				if(data.result=="Success")
				{
					hujiaoRow = data.map;
					debugger;
					//更新全局变量bck01为病人的挂号科室
					bck01 = hujiaoRow.bck01a;
					houzhenTbleList_houtai  = data.list;
					//调用声音服务和外显服务
					huJiao1(hujiaoRow);
					if (hujiaoRow.vaa18 && hujiaoRow.vaa19!='自费')
					{
						//针对医保病人--调用智慧医保的remind接口
						remind(hujiaoRow);
					}
					refreshListJiezhen_jiezhen();
				}
				else
				{
					if(data.result=="Failure" && data.resultMsg=="no-body")
					{
						layer.msg("暂时没有候诊的病人！",{time:3000,icon:0,skin: 'layui-layer-msg0'});
					}
					else if(data.result=="Failure" && data.resultMsg=="bad-tizhong")
					{
						//提示输入体重
						hujiaoRow = data.map;
						huJiao1(hujiaoRow);
						var data = {msg:"儿童需要录入体重"}
						laytplUrl_T(myurl + "/module/tizhong.html",data, function(data, html) {
							blood_index = layer.open({
								type : 1,
								title :"提示",
								area : [ "400px", "250px" ],
								shade : 0.1,
								content : html,
								closeBtn : 0,
								success : function() {
									$("#tizhong").focus();
									$("#saveTizhong").off("click").on("click",function(){
										layer.msg('加载中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500,skin: 'layui-layer-msg16'});
										debugger;
										var tizhong = $("#tizhong").val();
										if(tizhong && checkNumber(tizhong)){
											hujiaoRow.tizhong = tizhong;
											saveMoreInfo(hujiaoRow);
										}else{
											layer.msg("请输入正确的体重！",{time:3000,icon:0,skin: 'layui-layer-msg0'});
										}
									})
								}
							})
						})
					}
					else if(data.result=="Failure" && data.resultMsg=="bad-blood")
					{
						//提示输入血压
						hujiaoRow = data.map;
						huJiao1(hujiaoRow);
						var data = {msg:data.total+"岁以上病人需要录入血压值"}
						laytplUrl_T(myurl + "/module/blood_pressure.html",data, function(data, html) {
							blood_index = layer.open({
								type : 1,
								title :"提示",
								area : [ "400px", "250px" ],
								shade : 0.1,
								content : html,
								closeBtn : 0,
								success : function() {
									$("#blood_pressure").focus();
									$("#save_blood_pressure").off("click").on("click",function(){
										layer.msg('加载中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500,skin: 'layui-layer-msg16'});
										debugger;
										var blood = $("#blood_pressure").val();
										if(blood && checkNumber(blood.split("/")[0])&&checkNumber(blood.split("/")[1])){
											hujiaoRow.blood = blood;
											saveMoreInfo(hujiaoRow);
										}else{
											layer.msg("请输入正确的血压！",{time:3000,icon:0,skin: 'layui-layer-msg0'});
										}
									})
								}
							})
						})
					}
				}
			}
			reflushPatientWait();
		}
	});
}


//呼叫接诊

function callAfterReceive(row_t){
	$.ajax({
		url : rootUrl + "/clinicalreceptiontransfer/clinicvac1update",
		data : {
			lVAA07 : row_t.vac01,
			lVAA01 : row_t.vaa01,
			lSign : 0,
			lBCK01 : bck01,
			lBCE01 : bce01,
			lBCE02 : $.cookie("loginName"),
			lBCE03 : bce03
		},
		type : "post",
		dataType : 'json',
		async:false,
		success : function(data) {
			houzhenPatientList();
			myJienzhenPatientList();
			$("#hujiao").removeAttr("disabled");
			// 接诊后自动进入新开页面
			if (valueArr['p_100_105002_107'] == "1") {
				$("#myjiezhenTableList").jqGrid('setSelection',1);
				if(vac01!="null"){
					$("#newpage").click();
				}
			}
//////////////////////////////////////////////////呼叫病人
			huJiao1(row_t);
		}
	});
}

function loadZhenjinEditTable()
{
	//加载诊金编辑项目
	//查询诊查费列表
//	var zj_edit_row1;
//	var zj_edit_col1;
	debugger;
	var zhenjinList_app = [];
	var sendzhenjinList_app = [];
	var temp0 = {vac01:$("#vac01").val()};
	$.when(
			$.ajax({url:rootUrl+"/clidoctor/queryZjList",type:"get",dataType:"json",success:function(data1){
				zhenjinList_app=data1.list;
				}}),
			$.get(rootUrl+"/clidoctor/querySendZjByvac01",{params:JSON.stringify(temp0)},function(data2){
				sendzhenjinList_app=data2.list;
				})
		).done(
				function()
				{
					if (sendzhenjinList_app && sendzhenjinList_app.length>0)
					{
					for(var i =0;i<zhenjinList_app.length;i++)
					{
						zhenjinList_app[i].vaj01 = sendzhenjinList_app[0].vaj01;
					}
					$('#zhenjin_edit_container').resize(function(){
						$("#zhenjin_edit_table").setGridWidth($("#zhenjin_edit_container").width()*1);
					});
					$("#zhenjin_edit_table").GridUnload();
					$("#zhenjin_edit_table").jqGrid(
							{
								data : zhenjinList_app,
								datatype : "local",
								height : 'auto',
//								width : 'auto',
								autowidth : true,
//								forceFit:true,
//							    shrinkToFit:true,
								multiselect : true,
								multiboxonly:true,
								colModel : [
								            {
								            	label:'项目名称',
								            	name : 'bby05',
								            	align : 'left',
								            	width:'400'
								            },
								            {
								            	name : 'bdn01',
								            	hidden : true
								            },
								            {
								            	name : 'bby01',
								            	hidden : true
								            },
								            {
								            	name : 'vaj01',
								            	hidden : true
								            },
								            {
								            	label : '数量',
								            	name : 'amount',
								            	align : 'left',
								            	formatter : function(value, options, rData){
								       		    	if(value){
								       		    		 val =value;
								       		    	   }else{
								       		    		 val=1;
								       		    	   }
								       		    	return val;
								       		    	}
								            },
								            {
								            	label : '单价',
								            	name : 'bby25',
								            	align : 'left'
								            },
								            {
								            	label : '金额',
								            	name : 'bby25',
								            	align : 'left'
								            }
								            ],
//											beforeEditCell : function(rowid, cellname, value, iRow, iCol)
//											{
//												zj_edit_row1 = iRow;
//												zj_edit_col1 = iCol;
//											},
								            ondblClickRow : function(rowid, status)
								            {
								            	var row = $("#zhenjin_edit_table").jqGrid("getRowData", rowid);
								            },
								            loadComplete: function (data3) 
								            { 
								            	var rowIds = jQuery("#zhenjin_edit_table").jqGrid('getDataIDs');
								    				for(var j=0;j<rowIds.length;j++){
								    					var curRowData = jQuery("#zhenjin_edit_table").jqGrid('getRowData', rowIds[j]);
								    					if(sendzhenjinList_app[0].bby01==curRowData['bby01']){
								    						$('#zhenjin_edit_table').setSelection(rowIds[j]);
								    					}
								    			}

								            }
							})
					}
				}
		);
}

/**
 * 保存修改的诊金项目
 */
function saveEditZhenjin()
{
	$("#saveEditZhenjin").attr("disabled",true);
	//获取选中的诊金数据
	var rowId=$('#zhenjin_edit_table').jqGrid('getGridParam','selrow');
	var rowData = $('#zhenjin_edit_table').jqGrid('getRowData',rowId);
	var temp0 = {};
	var temp1 = [];temp1.push(rowData);
	temp0.vaj1List = temp1;
	temp0.vaj01 = rowData.vaj01;
	$.post(rootUrl+"/clidoctor/updateVajZjByvaj01",{params:JSON.stringify(temp0)},function(data){
		if(data)
		{
			if(data.result=="Success")
			{
				layer.msg("保存成功！", {time : 2000,
					icon : 1,
					skin: 'layui-layer-msg1'});
			}
			else if(data.result=="Failure")
			{
				layer.msg(data.resultMsg, {time : 2000,
					icon : 2,
					skin: 'layui-layer-msg2'});
			}
			loadZhenjinEditTable();
			$("#saveEditZhenjin").removeAttr("disabled");
		}
	});
}

//病人血压异常值提醒
function isNormalBloodPressure(rowid,rowData,tableid){
	//如果vcj04::integer >p_9999_9999_107  属于高压，给这行的字体置为红色;
	var hpress = rowData['vcj04'];
	var lpress = rowData['vcj05'];
	if(parseFloat(hpress) > parseFloat(valueArr["p_9999_9999_107"])){
		$("#"+tableid).jqGrid('setRowData', rowid, false, "hpress");
	}
	
	//如果vcj04::integer <p_9999_9999_108  or vcj05::integer <p_9999_9999_110  属于抵压，给这行的字体置为蓝色;
	else  if(parseFloat(hpress) < parseFloat(valueArr["p_9999_9999_108"]) || parseFloat(lpress) < parseFloat(valueArr["p_9999_9999_110"])) {
    	$("#"+tableid).jqGrid('setRowData', rowid, false, "lpress");
	}
	
}

//挂号有效期判断，vac72 和当前时间对比，超过当前时间则不能新开、编辑、删除等操作

function isOperateAdvice(){
	var table_id;
	var isoperate = true;
	var cur_tab = $("#all_patient").find(".active a").attr("href");
	if(cur_tab == "#mypatinent1"){
		table_id = "myjiezhenTableList";
		
	}else if(cur_tab == "#benkepatient1"){
		table_id = "jiezhenBenkeTable";
	}
	var selectedId = $("#"+table_id).jqGrid("getGridParam", "selrow")
	var selectRow =$("#"+table_id).jqGrid("getRowData", selectedId);
	if(new Date(Date.parse(selectRow.vac72)) < new Date())//获取病人挂号有效期
	{
		isoperate = false;
	}
	return isoperate;
}


//门诊病人检查详情信息展示
function checkDetailInfo()
{
	$("#check_detail_info").attr("disabled","disabled");
	var url = rootUrl + "/basicinformationquery/basequery";
    var params = {},para = {};
    params.sqlId = 10000043;
    params.vaa01 = $("#vaa01").val();
    para.params = JSON.stringify(params);
	$.when($.get(url, para)).done(function(data) {
		debugger;
		if(data.result == "Success"){
			$("#check_detail_info").removeAttr("disabled");
			if(data.list.length>0){
				//展示检查信息
				 showDatialEyeInfo(data.list);
			}else{
				layer.alert("该病人暂无检查信息", {
					icon : 0,
				});
				return ;
			}
		}else{
			layer.alert(data.resultMsg, {
				icon : 2,
			});
			$("#check_detail_info").removeAttr("disabled");
		}
	})
}
function showDatialEyeInfo(list){
	laytplUrl(myurl + "/module/menzhen_check_detail.html",list, function(data, html){
		var checkindex = layer.open(
		{
		type : 1,
		// scrollbar : false,
		title : "检查详情---"+$("#vaa05").text(),
		area :
		["60%", "90%"],
		shade : 0.1,
		maxmin : true,
		content : html,
		closeBtn : 1,
		zIndex : 5000,
		success : function()
		{
			$("#check_title_eye li:eq(0)").addClass("active");
			$("#check_title_eye li:eq(0)").trigger("click");
			$("#removeCheckinfo").on('click',function()
				{
					layer.close(checkindex);
				})
		},
		min : function(layero)
		{
			var times = layero.attr('times');
			$('#layui-layer-shade' + times).hide();
		},
		restore : function(layero)
		{
			var times = layero.attr('times');
			if ($('#layui-layer-shade' + times).css('display') == 'none')
			{
				$('#layui-layer-shade' + times).show();
			}
		},
		})

	});
}
function loadEyeInfo(tabName){
	layer.msg('加载中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500,skin: 'layui-layer-msg16'});
	var url = rootUrl + "/basicinformationquery/basequery";
    var params = {},para = {};
    params.sqlId = 10000044;
    params.vaa07 = $("#vac01").val();
    para.params = JSON.stringify(params);
	$.when($.get(url, para)).done(function(data) {
		debugger;
		if(data.result == "Success"){
			if(data.list.length>0){
				//展示检查信息
				showEyeToPage(data.list[0],tabName);
				
			}else{
				layer.alert("该病人暂无检查信息", {
					icon : 0,
				});
				return ;
			}
			
		}else{
			layer.alert(data.resultMsg, {
				icon : 2,
			});
		}
	})
}
function showEyeToPage(list,tabName){
	laytplUrl(myurl + "/module/eye_check.html",{},function(msg, html) {
		$("#"+tabName).empty().append(html);
		$("#check_form_info").find("select").select2();
		for(var key in list){
			var ele = $("#check_form_info").find("input[name="+key.toUpperCase()+"]").parents(".item_td");
			if(ele.length>0){
				ele.find("span").text("√");
				
			}
			$("#check_form_info").find("input[name="+key.toUpperCase()+"]").val(list[key]);
		}
		if(list.eye40){
			$("#check_form_info").find("#EYE40_S").val(list.eye40).trigger("change");
		}
	})
}
//表格td点击事件增加对勾
function addChoseFlagToTable(){
	$(".eye-jiancha-info .item_td").on("click",function(){
		if($(this).find("input").length<1){
			if(!$(this).text()){
				
				$(this).text("√");
			}else{
				$(this).text("");
			}
		}
	})
}
//保存时候组装数据
function leiDaodataSet(tableid){
	debugger;
	var result=[];
	$("#"+tableid).find("tbody tr").each(function(i,ele){
		var obj={};
		var classic;
		var valuearr=[];
		$(ele).find(".item_td").each(function(n,e){
			var iv = $(e).find("input").val()
			if(!!$(e).text()||!!iv){
				var ev = $(e).attr("value");
				if($(e).find("input").length >0){
					if(iv){
						ev = ev+'$'+iv;
					}
				}
				valuearr.push(ev);
				classic = valuearr.join("|");
			}
			
		})
		obj.name = $(ele).attr("data-item");
		obj.value = classic ?classic:"";
		result.push(obj);
	})
	return result;
}

//清空所有的td里面的对号
function emptyTdChose(){
	var tds = $(".eye-jiancha-info").find(".item_td");
	tds.each(function(i,e){
		if($(e).find("input").length>0){
			$(e).find("input").val("");
		}else{
			$(this).text("");
		}
	})
}

//眼科数据回填展示
function getEyeInfo(){
	debugger;
	var url =rootUrl+"/clidoctor/queryEye1";
	var params = {
		vac01:$("#vac01").val()
		}

	var para = {
			params : JSON.stringify(params)
	};
	$.when($.get(url, para)).done(function(json) {
		if(json.list.length>0){
			var data = json.list[0];
			//表格赋值
			$(".eye-jiancha-info").find("tr").each(function(i,e){
				var item = $(e).attr("data-item");
				if(item){
					if(data[item]){  //根据item取值
				    	var list = (data[item]).split("|");
				    	for(var j=0;j<list.length;j++){
				    		var temp = list[j];
				    		var tdindex = temp.split("$")[0];  //第一个为td的序号
				    		var tdval = temp.split("$")[1];  //第二个为td的值
				    		var td = $(e).find("td").eq(tdindex);
				    		if($(td).find("input").length>0){
				    			$(td).find("input").val(tdval);
				    		}else{
				    			
				    			$(td).text("√");
				    		}
				    		
				    	} 
					    	
						
					}
				}
			})
			
			//form赋值
			$(".eye-jiancha-info").find(".info-group-item").each(function(n,ele){
				var target = $(ele).find(".form-input");
				var targetid = $(ele).find(".form-input").attr("id");
				target.val(data[targetid]);
				
			})
			
		}
	})
}
function saveEyeInfo(){
	var leidao = leiDaodataSet("leidao_table");
	var lianban = leiDaodataSet("lianban_table");
	var shili = leiDaodataSet("shili_table");
	
	var url =rootUrl+"/clidoctor/updateEye1";
	var data =[];
	var obj = {
			name :"vac01",
			value:$("#vac01").val()
	}
	data.push(obj);
	var vcj = $("#triage_form_info").serializeArray(); // 自动将form表单封装成json
	data = data.concat(vcj);
	data = data.concat(leidao);
	data = data.concat(lianban);
	data = data.concat(shili);
	var dataStr = JSON.stringify(data);
	var para = {
			params :dataStr
	};
	$.when($.get(url, para)).done(function(data) {
		if(data.result == "Success"){
			layer.msg('保存成功',
					{
					time : 2000,
					icon : 1,
					skin: 'layui-layer-msg1'
					});
		}
	})
}
//分表处理业务，增加流程
function horateTransferData(){
	debugger;
	var def = $.Deferred();
	var dl1 =$("#date1_p").val();
	var dl2 =$("#dl2").val();
	var vak01s = getVak01s();
	if(vak01s.length>0){
		vak01s = vak01s.join(",");
		$.ajax({
			url : rootUrl + "/clideladvice/horate_transfer_data",
			type : "post",
			data :{
				"date1" : dl1,
				"date2" : dl2,
				"vak01" : vak01s,
			},
			dataType: "json",
			success: function (resp) {
				if (data.result != "Success")
				{
					layer.alert(data.ResultMsg,
							{
						icon : 2,
							});
				}
				def.resolve(resp);
			}
		});
	}else{
		def.resolve(vak01s);
	}
	return def.promise();
}
function getVak01s(){
	var vak01s=[];
	var checkedAdivce = $(".innerHead td input:checked");
	$(checkedAdivce).each(function(i,e){
		var subAdvice = $(e).parents("tbody").find(".yizhu_details");
		for(var j=0;j<subAdvice.length;j++){
			var str = $(subAdvice[j]).attr("data-info");
			var dobj = JSON.parse(str);
			if(dobj.vak01){
				vak01s.push(dobj.vak01);
			}
		}
	})
	return vak01s;
}

//调用外部程序
function Run(strPath) { 
	debugger;
	  var objShell = new ActiveXObject("wscript.shell"); 
	  objShell.Run(strPath); 
	  objShell = null; 
}
//查询住院号接口
function getVaa04(){
	  var def = $.Deferred();
	  var vaa01 = $("#vaa01").val();
      var param = {params:JSON.stringify({sqlId:10000065,vaa01:vaa01})};
      $.ajax({
      	type: "GET",
      	url: rootUrl+"/basicinformationquery/basequery",
      	data:param,
      	dataType: "json",
      	success: function (resp) {
      		def.resolve(resp.list);
      	}
      });
      return def.promise();
}
//调用pacs 接口
function pascReport(){
	debugger;
	$.when(
			getVaa04()
        ).done(function (data) {
        	$("#vaa04").val(data[0].vaa04);
//        	var href = "http://127.0.0.1:8080/reportsList.aspx?outputid=vaa03&inputid=vaa04";
        	var href = risReportParam.extris_repor.sysModUrl;
        	var cUrl = $.url(href);
        	var url = cUrl.attr('base')+cUrl.attr('path'); //http://allmarkedup.com
        	var para = cUrl.param();
        	var obj = {};
        	for(var i in para){
        		var key = hrefParam(para[i]);
        		obj[i] =  key;
        	}
        	var dUrl = url + '?' + $.param(obj);
        	window.open(dUrl);
    });
	
}

function hrefParam(temp){
	var hrefvalue;
	if(temp == "vaa01"){
		hrefvalue = $("#vaa01").val();
	}else if(temp == "vaa07"){
		hrefvalue = $("#vac01").val();
	}else if(temp == "vaa03"){
		hrefvalue =$("#patient_vaa03").text().trim();
	}
	else if(temp == "vaa04"){
		hrefvalue =$("#vaa04").val();
	}
	return hrefvalue;
}

//获取浏览器参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
//眼部信息查看
function eyeReportInfo(){
	debugger;
	var href = risReportParam.extris_repor.sysModUrl;
	var temp = href.split("@");
	var param;
	if(temp[1] == "vaa01"){
		if(!$("#"+temp[1]).val()){
			return layer.msg('请选择病人',
					{
					time : 3000,
					icon : 0,
					skin: 'layui-layer-msg0'
					});
		}
		param = $("#vaa01").val();
	}
	var url = temp[0]+param;
	window.open(url);
}

//病历信息
function emrExeReport(){
	  debugger;
	//  checkEmrReg();
	  //患者门诊流水号;医生登陆名;医生登陆科室ID，例如321322;U299;66
	  var vaa07 =$("#vac01").val();
	 if(vaa07 !='null'){
	   var loginname = loginName
	  var deptid = bck01;
	  //cid:110&username:xxh
	  var hrefurl = "EMRshell://"+vaa07+";"+loginName+";"+deptid;
	  window.location.href = hrefurl;
	   
	 }else{
	   return layer.msg('请选择病人',
	          {
	          time : 3000,
	          icon : 0,
	          skin: 'layui-layer-msg0'
	          });
	 }  
	  
}
//高视PACS
function pacsExeReport(){
	debugger;
	var vaa01 =$("#vaa01").val();
	if(vaa01){
		var loginname = loginName
		var deptid = bck01;
		var hrefurl = "PACSshell://"+"P"+vaa01;
		window.location.href = hrefurl;
	}else{
		return layer.msg('请选择病人',
		{
			time : 3000,
			icon : 0,
			skin: 'layui-layer-msg0'
		});
	}  
	
}
//根据病人科室选中当前科室
function getPatientDept(deptid){
	if(valueArr['p_100_105002_432'] ==1){
		$("#departmentList").val(deptid).trigger("change");	
	}
}


//是否可信任站点
function checkEmrReg(){ 
	  var regEdit = new RegEdit();  
	  var x = regEdit.regRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\FEIQ");  
	    
	  if(x == ""){  
	     alert("请先下载安装FeiQ.exe!");  
	     return false;  
	  }  
	  var s = x.substring(x.indexOf('"')+1,x.lastIndexOf('"'));  
}


function printByNiechenqi(){
	debugger;
	var data = {
		    "cmdid": "8",    /*  cmdid=7（打印）8（预览）9（格式设置）*/
		    "reportid": "4",/* 报表ID*/
		    "formatid": "4",/* 格式ID*/
		    "formatname": "广东省医疗机构收费收据", /* 格式名称*/
		    "datamode":'2',    /*  1: 后台查询  2：数据直接传输 */
//		    "dbcfg":{
//		        "provider":"postgresql", /*数据库类型*/
//		        "username": "postgres",   /*用户名*/
//		        "password": "cloudhealth2017",   /*密码*/
//		        "server": "120.76.241.24",     /*服务 */
//		        "database": "cloudhealth1",    /*库名 */
//		        "port":"5466"                /*端口*/
//		    },
		    "param": {
		        "vak01": "878497151397797888"  
		    },
		    "UserInfo":{
			"ID":"1130",   	/*用户ID*/
			"Code":"00782", 	/*用户编码*/
			"NameA":"张锐宁",	/*用户名*/
			"EmpId":"1145",	/*员工ID*/
			"EmpNo":"00782",	/*员工编号*/
			"EmpName":"张锐宁",	/*员工姓名*/
			"DeptId":"1",            /*科室ID*/
			"DeptNo":"0012", 	/*科室编号*/
			"DeptName":"体检科"	/*科室名称*/
		         },
		  };
	var data1 = {
			"cmdid": "9",    /*  cmdid=7（打印）8（预览）9（格式设置）*/
			"reportid": "4",/* 报表ID*/
			"formatid": "4",/* 格式ID*/
			"formatname": "广东省医疗机构收费收据", /* 格式名称*/
			"datamode":'2',    /*  1: 后台查询  2：数据直接传输 */
//		    "dbcfg":{
//		        "provider":"postgresql", /*数据库类型*/
//		        "username": "postgres",   /*用户名*/
//		        "password": "cloudhealth2017",   /*密码*/
//		        "server": "120.76.241.24",     /*服务 */
//		        "database": "cloudhealth1",    /*库名 */
//		        "port":"5466"                /*端口*/
//		    },
			"param": {
				"vak01": "878497151397797888"  
			},
			"UserInfo":{
				"ID":"1130",   	/*用户ID*/
				"Code":"00782", 	/*用户编码*/
				"NameA":"张锐宁",	/*用户名*/
				"EmpId":"1145",	/*员工ID*/
				"EmpNo":"00782",	/*员工编号*/
				"EmpName":"张锐宁",	/*员工姓名*/
				"DeptId":"1",            /*科室ID*/
				"DeptNo":"0012", 	/*科室编号*/
				"DeptName":"体检科"	/*科室名称*/
			},
			"datas": [
			            {"name":"病人信息",
						"datetype":{"type":1, /* 1 主数据 2 从数据*/
						                           "mastername":"",
						                           "mainfield":"",
						                           "fromfield":""
						                          },
						"data":[
						{"门诊号":"00005007","姓名":"李文东","性别":"1","年龄":"23"}]
						},
						{"name":"费用明细",
						               "datetype":{"type":1,       /* 1 主数据 2 从数据*/
						                           "mastername":"数据集名称1",
						                           "mainfield":"列名1",
						                           "fromfield":"列名3"
						                          },                    /* 1 主数据 2 从数据*/
						"data":[
						{"编号":"120100000-1","项目名称":"使用防褥疮气垫床加收","单价":"3.350000","数量":"1.0000","金额":"3.35"},
						{"编号":"120300001-4","项目名称":"氧气创面治疗","单价":"3.000000","数量":"1.0000","金额":"3.00"},
						{"编号":"018020","项目名称":"阿奇霉素针","单价":"2.850000","数量":"1.0000","金额":"2.85"},
						{"编号":"140070","项目名称":"0.9%氯化钠注射液","单价":"0.525000","数量":"1.0000","金额":"0.53"},
						{"编号":"011072","项目名称":"阿莫西林胶囊","单价":"0.087800","数量":"20.0000","金额":"1.76"},
						{"编号":"120300001-3","项目名称":"高流量给氧","单价":"3.000000","数量":"1.0000","金额":"3.00"},
						{"编号":"310300007*1","项目名称":"检影","单价":"4.750000","数量":"1.0000","金额":"4.75"}
						        ]
						}
		      ]
	};
	var data3 ={
	      "cmdid": "9",    /*  cmdid=7（打印）8（预览）9（格式设置）*/
	      "reportid": "4",/* 报表ID*/
	      "formatid": "4",/* 格式ID*/
	      "formatname": "广东省医疗机构收费收据", /* 格式名称*/
	      "datamode":'2',    /*  1: 后台查询  2：数据直接传输 */
	      "dbcfg":{
	            "provider":"postgresql", /*数据库类型*/
	            "username": "postgres",   /*用户名*/
	            "password": "cloudhealth2017",   /*密码*/
	            "server": "120.76.241.24",     /*服务 */
	            "database": "cloudhealth1",    /*库名 */
	            "port":"5466"                /*端口*/
	        },
	      "param": {
	        "vak01": "878497151397797888"  
	      },
	      "UserInfo":{
	        "ID":"0",     /*用户ID*/
	      },
	      "datas": [
	                  {"name":"病人信息",
	            "datetype":{"type":1, /* 1 主数据 2 从数据*/
	                                       "mastername":"",
	                                       "mainfield":"",
	                                       "fromfield":""
	                                      },
	            "data":[
	            {"门诊号":"00005007","姓名":"李文东","性别":"1","年龄":"23"}]
	            },
	            {"name":"费用明细",
	                           "datetype":{"type":1,       /* 1 主数据 2 从数据*/
	                                       "mastername":"数据集名称1",
	                                       "mainfield":"列名1",
	                                       "fromfield":"列名3"
	                                      },            /* 1 主数据 2 从数据*/
	            "data":[
	            {"编号":"120100000-1","收费名称":"使用防褥疮气垫床加收","单价":"3.350000","数量":"1.0000","结帐金额":"3.35"},
	            {"编号":"120300001-4","收费名称":"氧气创面治疗","单价":"3.000000","数量":"1.0000","结帐金额":"3.00"},
	            {"编号":"018020","收费名称":"阿奇霉素针","单价":"2.850000","数量":"1.0000","结帐金额":"2.85"},
	            {"编号":"140070","收费名称":"0.9%氯化钠注射液","单价":"0.525000","数量":"1.0000","结帐金额":"0.53"},
	            {"编号":"011072","收费名称":"阿莫西林胶囊","单价":"0.087800","数量":"20.0000","结帐金额":"1.76"},
	            {"编号":"120300001-3","收费名称":"高流量给氧","单价":"3.000000","数量":"1.0000","结帐金额":"3.00"},
	            {"编号":"310300007*1","收费名称":"检影","单价":"4.750000","数量":"1.0000","结帐金额":"4.75"}
	                    ]
	            },
		    {"name":"费目列表",
	                           "datetype":{"type":1,       /* 1 主数据 2 从数据*/
	                                       "mastername":"数据集名称1",
	                                       "mainfield":"列名1",
	                                       "fromfield":"列名3"
	                                      },            /* 1 主数据 2 从数据*/
	            "data":[
	            {"床位费":"0","西药费":"0","单价":"3.350000","中成药费":"1.0000","护理费":"3.35","检查费":"24.8","手术费":"12.5","理疗费":"20.5","诊查费":"0.59","输氧费":"30.5"}]
	            },
	             {"name":"支付方式",
	                           "datetype":{"type":1,       /* 1 主数据 2 从数据*/
	                                       "mastername":"数据集名称1",
	                                       "mainfield":"列名1",
	                                       "fromfield":"列名3"
	                                      },            /* 1 主数据 2 从数据*/
	            "data":[
	            {"缴款ID":"7151410380800","金额":"100.25","支付方式":"现金支付","faf01":"1.0000","vbl27":"2"}]
	            }
	          ]
	  }
	var str = JSON.stringify(data3);
	
	$.ajax({
		url: 'http://127.0.0.1:802/services/HisService?inputData='+str,
		data : {},
		dataType: "jsonp",
		type : "get",
        crossDomain: true,
        jsonp:"callback",    
        jsonpCallback:"success_jsonpCallback",  
		success : function(data) {
			if(data.result=='success'){
                alert('数据传输成功！');
            }else{
                alert(data.result)
            }
		},
		error: function (xhr, textStatus) {
            alert('服务请求失败！');
        },
	});
	

}
function loadddddd(){
//	$.ajax({
//        dataType: "jsonp",
//        crossDomain: true,
//        jsonp: "callback",
//        jsonpCallback: "success_jsonp",
//        type: 'get',
//        traditional: true,
//        data:{'rids':[4,5,1]},
//        url: "http://192.168.1.111:8080/cloudreportweb/cloud/printtemprest/commonPrintFormat",
//        async: true,
//        success: function (data) {
//
//        	console.log(data)
//        },
//        error: function () { 
//            console.log('错误了');
//          }
//    });
	   $.ajax({
	          url: "http://192.168.1.111:8080/cloudreportweb/cloud/printtemprest/commonPrintFormat?jsessionids="+jsessionids,
	          type: "get",
	          dataType: "jsonp",
	          async: false,
	          traditional: true,
	          data:{'rids':[4,5,1]},
	          success: function (d) { 
	            console.log(d);
	          },
	          error: function () { 
	            console.log('错误了');
	          }
	      });
	} 